package user;

import cars.Factory;
import operation.RentMgrSys;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-11-25
 * Time: 16:33
 */
public class Main {
    public static User login() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("===========欢迎来到汽车租赁系统=========");
        System.out.print("请输入用户名：");
        String name = scanner.nextLine();
        System.out.print("请输入登录密码：");
        int count = 0;
        while (count <= 3){
            String key = scanner.nextLine();
            if (key.equals("bit")) {
                System.out.println("登录成功，请输入你的身份：1 - 管理员，2 - 普通用户");
                int choice = scanner.nextInt();
                if (choice == 1) {
                    StoreMgr storeMgr = new StoreMgr(name);
                    if (storeMgr.UserName.compareTo(name) == 0){
                        return storeMgr;
                    }
                    System.out.println("抱歉，您非管理员，以下为普通用户界面");
                    return new Customer(name);
                } else {
                    return new Customer(name);
                }
            }
            if (count < 3){
                System.out.println("密码错误，请重新输入: ");
            }
            count++;
        }
        System.out.println("密码错误次数过多，退出系统");
        System.exit(0);
        return null;
    }
    public static void main(String[] args) {
        //new一个工厂对象
        Factory factory = new Factory();
        //登录界面
        User user = login();
        while (true){
            //user菜单
            int choice = user.menu();
            //user对应功能
            user.doWork(choice, factory);
        }
    }
}
